// packageB/member/income/new_team_bonus/new_team_bonus.js
var app = getApp();
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    active:0,
    display1: -1,
    display2:-1,

    list_title:[],
    list_data:[],

    requestData:{},
    pageData:{},

    page:1,
    total_page:0,
    isLoadMore:true

  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function (options) {
    this.getData();
  },

  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function () {

  },

  /**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function () {

  },

  /**
	 * 生命周期函数--监听页面隐藏
	 */
  onHide: function () {

  },
  changeTags(e){
    console.log(e.detail.index,this.data.active);
    this.initData();
    this.data.active = e.detail.index;
    this.getData(e.detail.index);
  },
  openDetail(e) {
    console.log(e.currentTarget.dataset.ind2);
    console.log(this.data.display1);
    if ((e.currentTarget.dataset.ind1 == this.data.display1) && (e.currentTarget.dataset.ind2 == this.data.display2)) {
      this.setData({
        display1: '-1',
        display2: '-2'
      });
      return;
    }
    this.setData({
      display1: e.currentTarget.dataset.ind1,
      display2: e.currentTarget.dataset.ind2
    });
  },

  /**
	 * 生命周期函数--监听页面卸载
	 */
  onUnload: function () {

  },

  initData(){
    this.data.page = 1;
    this.data.requestData={};
  },

  async getData(dividend_type=null){
			
    if(dividend_type != null){
      this.data.requestData.dividend_type = dividend_type;
    }
    let urlStr = app.getNetAddresss('plugin.team-sztt.api.index');
    app._getNetWork({
      url: urlStr,
      data:this.data.requestData,
      success: (response) => {
        let res = response.data;
        if(res.result !=1 ){
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 1000
          });
          return;
        }
        this.data.isLoadMore = true;
        this.data.total_page = res.data.lastpage;
        if (!this.data.total_page) {
          this.data.isLoadMore = false;
          this.data.total_page = 0;
        }
        wx.setNavigationBarTitle({
          title: res.data.plugin_name,
        });
        //this.fun.setWXTitle(res.data.plugin_name);
        this.setData({
          pageData:res.data,
          list_title:res.data.list_title,
          list_data:res.data.list
        });
      }
    });

  },
  getMoreData(){
    if (this.data.page == this.data.total_page) {
      wx.showToast({
        title: '没有更多',
        icon: 'none',
        duration: 1000
      });
      this.setData({isLoadMore:false});
      return;
    }
    this.data.page++;
    let urlStr = app.getNetAddresss('plugin.team-sztt.api.index');
    let json = {page: this.data.page };
    Object.assign(json,this.data.requestData);
    app._getNetWork({
      url: urlStr,
      data:json,
      success: (response) => {
        let res = response.data;
        if(res.result !=1){
          this.data.page--;
          this.data.isLoadMore = false;
          return;
        }
        this.data.isLoadMore = true;
        this.data.total_page = res.data.lastpage;
        if (!this.data.total_page) {
          this.data.total_page = 0;
        }
        //this.fun.setWXTitle(res.data.plugin_name);
        let list_data = this.data.list_data.concat(res.data.list);
        this.setData({
          list_data
        });
      }
    });




  },

  /**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
  onPullDownRefresh: function () {

  },

  /**
	 * 页面上拉触底事件的处理函数
	 */
  onReachBottom: function () {
    if (this.data.isLoadMore) {
      this.getMoreData();
    } else {
      wx.showToast({
        title: '没有更多数据',
        icon: 'none'
      });
    }
  },

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function () {

  }
});